
function BattleSpecialMageBlack()
{
RenderMap();

  BattleName(); 
  DrawPlayerStats();
  
  var BattleMenumag = new Menu();
  BattleMenumag.font         = Font;
  BattleMenumag.window_style = WindowStyle;
  BattleMenumag.arrow        = Arrow;
  if (Player.active == "Player1")
  {
    if (Playerbmagic.fire == true)
    {
    BattleMenumag.addItem("Fire", BattleSpecialMageFire);
    }
    if (Playerbmagic.ice == true)
    {
    BattleMenumag.addItem("Ice", BattleSpecialMageIce);
    }
    if (Playerbmagic.lit == true)
    {
    BattleMenumag.addItem("Lit", BattleSpecialMageLit);
    }
    if (Playerbmagic.earth == true)
    {
    BattleMenumag.addItem("Earth", BattleSpecialMageEarth);
    }
    if (Playerbmagic.drainhp == true)
    {
    BattleMenumag.addItem("Drain Hp", BattleSpecialMageDrainHp);
    }
    if (Playerbmagic.fire2 == true)
    {
    BattleMenumag.addItem("Fire 2", BattleSpecialMageFire2);
    }
    if (Playerbmagic.ice2 == true)
    {
    BattleMenumag.addItem("Ice 2", BattleSpecialMageIce2);
    }
    if (Playerbmagic.lit2 == true)
    {
    BattleMenumag.addItem("Lit 2", BattleSpecialMageLit2);
    }
    if (Playerbmagic.earth2 == true)
    {
    BattleMenumag.addItem("Earth 2", BattleSpecialMageEarth2);
    }
    if (Playerbmagic.drainmp == true)
    {
    BattleMenumag.addItem("Drain Mp", BattleSpecialMageDrainMp);
    }    
    if (Playerbmagic.aero == true)
    {
    BattleMenumag.addItem("Aero", BattleSpecialMageAero);
    }    
    if (Playerbmagic.water == true)
    {
    BattleMenumag.addItem("Water", BattleSpecialMageWater);
    }    
    if (Playerbmagic.fire3 == true)
    {
    BattleMenumag.addItem("Fire 3", BattleSpecialMageFire3);
    }
    if (Playerbmagic.ice3 == true)
    {
    BattleMenumag.addItem("Ice 3", BattleSpecialMageIce3);
    }
    if (Playerbmagic.lit3 == true)
    {
    BattleMenumag.addItem("Lit 3", BattleSpecialMageLit3);
    }
    if (Playerbmagic.earth3 == true)
    {
    BattleMenumag.addItem("Earth 3", BattleSpecialMageEarth3);
    }
    if (Playerbmagic.aera == true)
    {
    BattleMenumag.addItem("Aera", BattleSpecialMageAera);
    }
    if (Playerbmagic.tidelwave == true)
    {
    BattleMenumag.addItem("Tidel Wave", BattleSpecialMageTidelWave);
    }
    if (Playerbmagic.metra == true)
    {
    BattleMenumag.addItem("Metra", BattleSpecialMageMetra);
    }
    if (Playerbmagic.alpha == true)
    {
    BattleMenumag.addItem("Alpha", BattleSpecialMageAlpha);
    }
    if (Playerbmagic.omega == true)
    {
    BattleMenumag.addItem("Omega", BattleSpecialMageOmega);
    }  
  }
  else if (Player.active == "Player2")
  {
    if (Player2bmagic.fire == true)
    {
    BattleMenumag.addItem("Fire", BattleSpecialMageFire);
    }
    if (Player2bmagic.ice == true)
    {
    BattleMenumag.addItem("Ice", BattleSpecialMageIce);
    }
    if (Player2bmagic.lit == true)
    {
    BattleMenumag.addItem("Lit", BattleSpecialMageLit);
    }
    if (Player2bmagic.earth == true)
    {
    BattleMenumag.addItem("Earth", BattleSpecialMageEarth);
    }
    if (Player2bmagic.drainhp == true)
    {
    BattleMenumag.addItem("Drain Hp", BattleSpecialMageDrainHp);
    }
    if (Player2bmagic.fire2 == true)
    {
    BattleMenumag.addItem("Fire 2", BattleSpecialMageFire2);
    }
    if (Player2bmagic.ice2 == true)
    {
    BattleMenumag.addItem("Ice 2", BattleSpecialMageIce2);
    }
    if (Player2bmagic.lit2 == true)
    {
    BattleMenumag.addItem("Lit 2", BattleSpecialMageLit2);
    }
    if (Player2bmagic.earth2 == true)
    {
    BattleMenumag.addItem("Earth 2", BattleSpecialMageEarth2);
    }
    if (Player2bmagic.drainmp == true)
    {
    BattleMenumag.addItem("Drain Mp", BattleSpecialMageDrainMp);
    }    
    if (Player2bmagic.aero == true)
    {
    BattleMenumag.addItem("Aero", BattleSpecialMageAero);
    }    
    if (Player2bmagic.water == true)
    {
    BattleMenumag.addItem("Water", BattleSpecialMageWater);
    }    
    if (Player2bmagic.fire3 == true)
    {
    BattleMenumag.addItem("Fire 3", BattleSpecialMageFire3);
    }
    if (Player2bmagic.ice3 == true)
    {
    BattleMenumag.addItem("Ice 3", BattleSpecialMageIce3);
    }
    if (Player2bmagic.lit3 == true)
    {
    BattleMenumag.addItem("Lit 3", BattleSpecialMageLit3);
    }
    if (Player2bmagic.earth3 == true)
    {
    BattleMenumag.addItem("Earth 3", BattleSpecialMageEarth3);
    }
    if (Player2bmagic.aera == true)
    {
    BattleMenumag.addItem("Aera", BattleSpecialMageAera);
    }
    if (Player2bmagic.tidelwave == true)
    {
    BattleMenumag.addItem("Tidel Wave", BattleSpecialMageTidelWave);
    }
    if (Player2bmagic.metra == true)
    {
    BattleMenumag.addItem("Metra", BattleSpecialMageMetra);
    }
    if (Player2bmagic.alpha == true)
    {
    BattleMenumag.addItem("Alpha", BattleSpecialMageAlpha);
    }
    if (Player2bmagic.omega == true)
    {
    BattleMenumag.addItem("Omega", BattleSpecialMageOmega);
    }  
  }
  else if (Player.active == "Player3")
  {
    if (Player3bmagic.fire == true)
    {
    BattleMenumag.addItem("Fire", BattleSpecialMageFire);
    }
    if (Player3bmagic.ice == true)
    {
    BattleMenumag.addItem("Ice", BattleSpecialMageIce);
    }
    if (Player3bmagic.lit == true)
    {
    BattleMenumag.addItem("Lit", BattleSpecialMageLit);
    }
    if (Player3bmagic.earth == true)
    {
    BattleMenumag.addItem("Earth", BattleSpecialMageEarth);
    }
    if (Player3bmagic.drainhp == true)
    {
    BattleMenumag.addItem("Drain Hp", BattleSpecialMageDrainHp);
    }
    if (Player3bmagic.fire2 == true)
    {
    BattleMenumag.addItem("Fire 2", BattleSpecialMageFire2);
    }
    if (Player3bmagic.ice2 == true)
    {
    BattleMenumag.addItem("Ice 2", BattleSpecialMageIce2);
    }
    if (Player3bmagic.lit2 == true)
    {
    BattleMenumag.addItem("Lit 2", BattleSpecialMageLit2);
    }
    if (Player3bmagic.earth2 == true)
    {
    BattleMenumag.addItem("Earth 2", BattleSpecialMageEarth2);
    }
    if (Player3bmagic.drainmp == true)
    {
    BattleMenumag.addItem("Drain Mp", BattleSpecialMageDrainMp);
    }    
    if (Player3bmagic.aero == true)
    {
    BattleMenumag.addItem("Aero", BattleSpecialMageAero);
    }    
    if (Player3bmagic.water == true)
    {
    BattleMenumag.addItem("Water", BattleSpecialMageWater);
    }    
    if (Player3bmagic.fire3 == true)
    {
    BattleMenumag.addItem("Fire 3", BattleSpecialMageFire3);
    }
    if (Player3bmagic.ice3 == true)
    {
    BattleMenumag.addItem("Ice 3", BattleSpecialMageIce3);
    }
    if (Player3bmagic.lit3 == true)
    {
    BattleMenumag.addItem("Lit 3", BattleSpecialMageLit3);
    }
    if (Player3bmagic.earth3 == true)
    {
    BattleMenumag.addItem("Earth 3", BattleSpecialMageEarth3);
    }
    if (Player3bmagic.aera == true)
    {
    BattleMenumag.addItem("Aera", BattleSpecialMageAera);
    }
    if (Player3bmagic.tidelwave == true)
    {
    BattleMenumag.addItem("Tidel Wave", BattleSpecialMageTidelWave);
    }
    if (Player3bmagic.metra == true)
    {
    BattleMenumag.addItem("Metra", BattleSpecialMageMetra);
    }
    if (Player3bmagic.alpha == true)
    {
    BattleMenumag.addItem("Alpha", BattleSpecialMageAlpha);
    }
    if (Player3bmagic.omega == true)
    {
    BattleMenumag.addItem("Omega", BattleSpecialMageOmega);
    }  
  }
  BattleMenumag.addItem("Cancel", GoToActivePlayer);
  BattleMenumag.execute(5, 355, 235, 120);
}
function BattleSpecialMageFire()
{
CheckMp("Lv1");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Fire"
  Player.attacktype = "Fire"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageIce()
{
CheckMp("Lv1");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Ice"
  Player.attacktype = "Ice"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageLit()
{
CheckMp("Lv1");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Lit"
  Player.attacktype = "Lit"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageEarth()
{
CheckMp("Lv1.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Earth"
  Player.attacktype = "Earth"
  TakeoutDamage()
  }
}
function BattleSpecialMageDrainHp()
{
CheckMp("Lv1.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Drain Hp"
  Player.attacktype = ""
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageFire2()
{
CheckMp("Lv2");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Fire 2"
  Player.attacktype = "Fire"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageIce2()
{
CheckMp("Lv2");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Ice 2"
  Player.attacktype = "Ice"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageLit2()
{
CheckMp("Lv2");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Lit 2"
  Player.attacktype = "Lit"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageEarth2()
{
CheckMp("Lv2.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Earth 2"
  Player.attacktype = "Earth"
  TakeoutDamage()
  }
}
function BattleSpecialMageDrainMp()
{
CheckMp("Lv1");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {    
  Player.temp = "Drain Mp"
  Player.attacktype = ""
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageAero()
{
CheckMp("Lv3");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Aero"
  Player.attacktype = "Wind"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageWater()
{
CheckMp("Lv3");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Water"
  Player.attacktype = "Water"
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageFire3()
{
CheckMp("Lv3.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Fire 3"
  Player.attacktype = "Fire"
  TakeoutDamage()
  }
}
function BattleSpecialMageIce3()
{
CheckMp("Lv3.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Ice 3"
  Player.attacktype = "Ice"
  TakeoutDamage()
  }
}
function BattleSpecialMageLit3()
{
CheckMp("Lv3.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Lit 3"
  Player.attacktype = "Lit"
  TakeoutDamage()
  }
}
function BattleSpecialMageEarth3()
{
CheckMp("Lv4");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Earth 3"
  Player.attacktype = "Earth"
  TakeoutDamage()
  }
}
function BattleSpecialMageAera()
{
CheckMp("Lv4.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Aera"
  Player.attacktype = "Wind"
  TakeoutDamage()
  }
}
function BattleSpecialMageTidelWave()
{
CheckMp("Lv4.5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Tidel Wave"
  Player.attacktype = "Water"
  TakeoutDamage()
  }
}
function BattleSpecialMageMetra()
{
CheckMp("Lv5");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Metra"
  Player.attacktype = ""
  TakeoutDamage()
  }
}
function BattleSpecialMageAlpha()
{
CheckMp("Lv6");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Alpha"
  Player.attacktype = ""
  BattleSpecialMageBtarget()
  }
}
function BattleSpecialMageOmega()
{
CheckMp("Lv7");
  if (Player.needmp > Player.actmp)
  {
  Talk_Window("You don't have enough Mp!", "blank.png");
  GoToActivePlayer();
  }
  else
  {
  Player.temp = "Omega"
  Player.attacktype = ""
  TakeoutDamage();
  }
}

function BattleSpecialMageBtarget()
{
Player.BMenuTemp = true;

RenderMap();

  BattleName(); 
  DrawPlayerStats();
  
  var BattleMenumag = new BMenu();
  BattleMenumag.font         = Font;
  BattleMenumag.window_style = WindowStyle;
  BattleMenumag.arrow        = Arrow;
  if (Monster1.hp > 0)
  {
  BattleMenumag.addItem(Monster1.name, BattleSpecialMageBtarget1);
  }
  if (Monster2.hp > 0)
  {
  BattleMenumag.addItem(Monster2.name, BattleSpecialMageBtarget2);
  }
  if (Monster3.hp > 0)
  {
  BattleMenumag.addItem(Monster3.name, BattleSpecialMageBtarget3);
  }
  if (Monster4.hp > 0)
  {
  BattleMenumag.addItem(Monster4.name, BattleSpecialMageBtarget4);
  }
  BattleMenumag.addItem("Cancel", GoToActivePlayer);  
  BattleMenumag.execute(5, 355, 235, 120);
}
function BattleSpecialMageBtarget1()
{
Player.mtarget = "Monster1"
Player.mhp = Monster1.hp;
Player.mmp = Monster1.mp;
Player.mmag = Monster1.mag;
TakeoutDamage();
}
function BattleSpecialMageBtarget2()
{
Player.mtarget = "Monster2"
Player.mhp = Monster2.hp;
Player.mmp = Monster2.mp;
Player.mmag = Monster2.mag;
TakeoutDamage();
}
function BattleSpecialMageBtarget3()
{
Player.mtarget = "Monster3"
Player.mhp = Monster3.hp;
Player.mmp = Monster3.mp;
Player.mmag = Monster3.mag;
TakeoutDamage();
}
function BattleSpecialMageBtarget4()
{
Player.mtarget = "Monster4"
Player.mhp = Monster4.hp;
Player.mmp = Monster4.mp;
Player.mmag = Monster4.mag;
TakeoutDamage();
}

function TakeoutDamage()
{
GetMagStats();
Player.mathtemp = Math.random()/5 + 0.9;
  if (Player.active == "Player1")
  {
    if (Player.DPlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player2")
  {
    if (Player2.DPlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  else if (Player.active == "Player3")
  {
    if (Player3.DPlate == true)
    {
    Player.mathtemp = Player.mathtemp*1.5;
    }
  }
  
  if (Player.temp == "Fire")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*Player.mattacktemp/Player.mmag*1.2)
  ReduceMp("Lv1");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Ice")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*Player.mattacktemp/Player.mmag*1.2)
  ReduceMp("Lv1");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Lit")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*Player.mattacktemp/Player.mmag*1.2)
  ReduceMp("Lv1");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Earth")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*1.4)
  ReduceMp("Lv1.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Drain Hp")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*1.8)
    if (Player.attackdamage >= Player.mhp)
    {
    Player.attackdamage = Player.mhp;
    }          
  ReduceMp("Lv1.5");
  HurtMonster(Player.attackdamage);
  Player.playertemp = Player.active;
  HealPerson(Player.attackdamage);
  }
  else if (Player.temp == "Fire 2")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*3.2)
  ReduceMp("Lv2");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Ice 2")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*3.2)
  ReduceMp("Lv2");
  HurtMonster(Player.attackdamage);
  }  
  else if (Player.temp == "Lit 2")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*3.2)
  ReduceMp("Lv2");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Earth 2")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*4.0)
  ReduceMp("Lv2.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Drain Mp")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*.5)
    if (Player.attackdamage >= Player.mmp)
    {
    Player.attackdamage = Player.mmp;
    }
  ReduceMp("Lv1");
  HurtMonsterMp(Player.attackdamage);
  HealPersonMp(Player.attackdamage);
  }
  else if (Player.temp == "Aero")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*6)
  ReduceMp("Lv3");
  HurtMonster(Player.attackdamage);
  }  
  else if (Player.temp == "Water")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*6)
  ReduceMp("Lv3");
  HurtMonster(Player.attackdamage);
  }  
  else if (Player.temp == "Fire 3")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*10)
  ReduceMp("Lv3.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Ice 3")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*10)
  ReduceMp("Lv3.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Lit 3")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*10)
  ReduceMp("Lv3.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Earth 3")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*12)
  ReduceMp("Lv4");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Aera")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*15)
  ReduceMp("Lv4.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Tidel Wave")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*15)
  ReduceMp("Lv4.5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Metra")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*22)
  ReduceMp("Lv5");
  HurtAllMonster(Player.attackdamage);
  }
  else if (Player.temp == "Alpha")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*30)
  ReduceMp("Lv6");
  HurtMonster(Player.attackdamage);
  }
  else if (Player.temp == "Omega")
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*35)
  ReduceMp("Lv7");
  HurtAllMonster(Player.attackdamage);
  }  

  else if (Player.temp == Player.cmagic.telekinesis)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*1.5)
  ReduceMp("Lv1");
  HurtMonster(Player.attackdamage);  
  }  
  else if (Player.temp == Player.cmagic.diease)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*2.5)
  ReduceMp("Lv1.5");
  HurtMonster(Player.attackdamage);
  }  
  else if (Player.temp == Player.cmagic.explode)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*10)
  ReduceMp("Lv3");
  HurtAllMonster(Player.attackdamage);
  }  
  else if (Player.temp == Player.cmagic.explode2)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*14)
  ReduceMp("Lv4");
  HurtAllMonster(Player.attackdamage);
  }  
  else if (Player.temp == Player.cmagic.plague)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp*17)
  ReduceMp("Lv4.5");
  HurtAllMonster(Player.attackdamage);
  }  
  else if (Player.temp == Player.cmagic.flare)
  {
  Player.attackdamage = Math.floor(Player.mathtemp*Player.mattacktemp/Player.mmag*Player.mattacktemp*25)
  ReduceMp("Lv5");
  HurtMonster(Player.attackdamage);
  }  
  
BattleMenu_Itemused();
}

function HurtMonster(hurtmonster)
{
RenderMap();

  if (Player.mtarget == "Monster1")
  {
    if (Monster1.weak == Player.attacktype)
    {
    hurtmonster = hurtmonster*1.5;  
    }
    if (Monster1.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster1.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster1.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }

  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster1.hp = Monster1.hp - hurtmonster; 
  ShowMonster1Damage(hurtmonster)
  }  
  else if (Player.mtarget == "Monster2")
  {
    if (Monster2.weak == Player.attacktype)
    {
    hurtmonster = hurtmonster*1.5;  
    }
    if (Monster2.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster2.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster2.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }

  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster2.hp = Monster2.hp - hurtmonster; 
  ShowMonster2Damage(hurtmonster)
  }  
  else if (Player.mtarget == "Monster3")
  {
    if (Monster3.weak == Player.attacktype)
    {
    hurtmonster = hurtmonster*1.5;  
    }    
    if (Monster3.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster3.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster3.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster3.hp = Monster3.hp - hurtmonster;
  ShowMonster3Damage(hurtmonster)
  }  
  else if (Player.mtarget == "Monster4")
  {
    if (Monster4.weak == Player.attacktype)
    {
    hurtmonster = hurtmonster*1.5;  
    }
    if (Monster4.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster4.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster4.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }
    
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster4.hp = Monster4.hp - hurtmonster; 
  ShowMonster4Damage(hurtmonster)
  }  
}
function HurtAllMonster(hurtmonster)
{
RenderMap();
Player.attackdamage = hurtmonster;
Player.attackdamage2 = hurtmonster;
  if (Monster1.hp > 0)
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
    if (Monster1.weak == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*1.5;  
    }
    if (Monster1.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster1.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster1.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }

  Player.attackdamage2 = Math.floor(Player.attackdamage*Player.mattacktemp/Monster1.mag*(Math.random()/5 + .9));  
  Monster1.hp = Monster1.hp - Player.attackdamage2;
  if (Player.attackdamage < 0)
  {
  HpFont.drawTextBox (Monster1.posx, Monster1.posy, 500, 100, 5, Player.attackdamage2*(0 - 1));
  }
  else
  { 
  Font.drawTextBox (Monster1.posx, Monster1.posy, 500, 100, 5, Player.attackdamage2);
  }
  DrawPlayerStats();
  BattleName();
  FlipScreen();
  Delay(1000);
  IsMonster1Dead();  
  }
RenderMap();
Player.attackdamage = hurtmonster;
Player.attackdamage2 = hurtmonster;
  if (Monster2.hp > 0)
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
    if (Monster2.weak == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*1.5;  
    }
    if (Monster2.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster2.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster2.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }
    
  Player.attackdamage2 = Math.floor(Player.attackdamage*Player.mattacktemp/Monster2.mag*(Math.random()/5 + .9));  
  Monster2.hp = Monster2.hp - Player.attackdamage2; 
  if (Player.attackdamage < 0)
  {
  HpFont.drawTextBox (Monster2.posx, Monster2.posy, 500, 100, 5, Player.attackdamage2*(0 - 1));
  }
  else
  { 
  Font.drawTextBox (Monster2.posx, Monster2.posy, 500, 100, 5, Player.attackdamage2);
  }
  DrawPlayerStats();
  BattleName();
  FlipScreen();
  Delay(1000);
  IsMonster2Dead();  
  }
RenderMap();
Player.attackdamage = hurtmonster;
Player.attackdamage2 = hurtmonster;
  if (Monster3.hp > 0)
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
    if (Monster3.weak == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*1.5;  
    }
    if (Monster3.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster3.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster3.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }
    
  Player.attackdamage2 = Math.floor(Player.attackdamage*Player.mattacktemp/Monster3.mag*(Math.random()/5 + .9));  
  Monster3.hp = Monster3.hp - Player.attackdamage2; 
  if (Player.attackdamage < 0)
  {
  HpFont.drawTextBox (Monster3.posx, Monster3.posy, 500, 100, 5, Player.attackdamage2*(0 - 1));
  }
  else
  { 
  Font.drawTextBox (Monster3.posx, Monster3.posy, 500, 100, 5, Player.attackdamage2);
  }
  DrawPlayerStats();
  BattleName();
  FlipScreen();
  Delay(1000);
  IsMonster3Dead();  
  }
RenderMap();
Player.attackdamage = hurtmonster;
Player.attackdamage2 = hurtmonster;
  if (Monster4.hp > 0)
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
    if (Monster4.weak == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*1.5;  
    }
    if (Monster4.strong == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage/2;  
    }
    if (Monster4.immune == Player.attacktype)
    {
    Player.attackdamage = 0;  
    }
    if (Monster4.absorb == Player.attacktype)
    {
    Player.attackdamage = Player.attackdamage*(0 - 1);  
    }

  Player.attackdamage2 = Math.floor(Player.attackdamage*Player.mattacktemp/Monster4.mag*(Math.random()/5 + .9));  
  Monster4.hp = Monster4.hp - Player.attackdamage2; 
  if (Player.attackdamage < 0)
  {
  HpFont.drawTextBox (Monster4.posx, Monster4.posy, 500, 100, 5, Player.attackdamage2*(0 - 1));
  }
  else
  { 
  Font.drawTextBox (Monster4.posx, Monster4.posy, 500, 100, 5, Player.attackdamage2);
  }
  DrawPlayerStats();
  BattleName();
  FlipScreen();
  Delay(1000);
  IsMonster4Dead();  
  }
}
function HurtMonsterMp(hurtmonstermp)
{
RenderMap();

  if (Player.mtarget == "Monster1")
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster1.mp = Monster1.mp - hurtmonstermp; 
  Font.drawText(Monster1.posx, Monster1.posy, hurtmonstermp);
  FlipScreen();
  Delay(500);
  }  
  else if (Player.mtarget == "Monster2")
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Font.drawText(Monster2.posx, Monster2.posy, hurtmonstermp);
  FlipScreen();
  Delay(500);
  }  
  else if (Player.mtarget == "Monster3")
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Font.drawText(Monster3.posx, Monster3.posy, hurtmonstermp);
  FlipScreen();
  Delay(500);
  }  
  else if (Player.mtarget == "Monster4")
  {
  WindowStyle.drawWindow(5, 5, 235, 12);
  Font.drawText(7, 7, Player.temp);
  Monster4.mp = Monster4.mp - hurtmonstermp; 
  Font.drawText(Monster4.posx, Monster4.posy, hurtmonstermp);
  FlipScreen();
  Delay(500);
  }  
}

function HealPerson(healing)
{
  if (Player.active == "Player1")
  {
  Player.hp = Player.hp + healing;    
      if (Player.hp > Player.maxhp)
      {
      Player.hp = Player.maxhp;
      }
  Player.playertemp = "Player1"
  ShowHeathGain(healing);
  }
  else if (Player.active == "Player2")
  {
  Player2.hp = Player2.hp + healing;    
      if (Player2.hp > Player2.maxhp)
      {
      Player2.hp = Player2.maxhp;
      }
  Player.playertemp = "Player2"
  ShowHeathGain(healing);
  }
  else if (Player3.active == "Player3")
  {
  Player3.hp = Player3.hp + healing;    
      if (Player3.hp > Player3.maxhp)
      {
      Player3.hp = Player3.maxhp;
      }
  Player.playertemp = "Player2"
  ShowHeathGain(healing);
  }
}
function HealPersonMp(healingmp)
{
Player.playertemp = Player.active;
  if (Player.active == "Player1")
  {
  Player.mp = Player.mp + healingmp;    
      if (Player.mp > Player.maxmp)
      {
      Player.mp = Player.maxmp;
      }
  }
  else if (Player.active == "Player2")
  {
  Player2.mp = Player2.mp + healingmp;    
      if (Player2.mp > Player2.maxmp)
      {
      Player2.mp = Player2.maxmp;
      }
  }
  else if (Player.active == "Player3")
  {
  Player3.mp = Player3.mp + healingmp;    
      if (Player3.mp > Player3.maxmp)
      {
      Player3.mp = Player3.maxmp;
      }
  }

ShowMpGain(healingmp);
}

function GetMagStats()
{
  if (Player.active == "Player1")
  {
  Player.mattacktemp = Player.mattack;
  Player.mluck = Player.luck;
  }
  else if (Player.active == "Player2")
  {
  Player.mattacktemp = Player2.mattack;  
  Player.mluck = Player2.luck;
  }
  else if (Player.active == "Player3")
  {
  Player.mattacktemp = Player3.mattack;  
  Player.mluck = Player3.luck;
  }
}  
